<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js" type="application/javascript"></script>
</head>
<body>
  <div id="app">
    <!-- <el-dialog :dialog-visible.sync="dialogVisible"></el-dialog> -->
    <!-- 父组件传属性,传事件监听到子组件当中 -->
    <el-dialog :dialog-visible="dialogVisible" @close="dialogVisible = false"></el-dialog>
  </div>
</body>
<script>
  // 不用$attrs和$listeners的写法
  /*Vue.component('el-dialog',{
    props: ['dialogVisible'],
    template: `
      <div v-if="dialogVisible">
        <a @click="$emit('update:dialogVisible', false)">关闭</a>
        <div>内容</div>
      </div>
    `
  })*/
  Vue.component('el-dialog',{
    // props: ['dialogVisible'],
    // 子组件通过$attrs进行接收数据,通过$listeners调用父组件的监听方法
    template: `
      <div v-if="$attrs['dialog-visible']">
        <a @click="$listeners.close()">关闭</a>
        <div>内容</div>
      </div>
    `
  })
  new Vue({
    el: '#app',
    data(){
      return {
        dialogVisible: true
      }
    },
    methods: {
    }
  })
</script>
</html>
